from flask import Blueprint, jsonify, request
from conf.comm import sqlalchemy_context
from database import *
import json

# 实例化
bp_course = Blueprint('course', __name__)


@bp_course.route('/cateM', methods=['GET', 'POST'])
@sqlalchemy_context()
def cateM():
    if request.method == "POST":
        data = request.data
        if data:
            data = json.loads(data)
        else:
            data = request.form
        cate = Cate(name=data['name'], level=data['level'], parent=data['parent'], params=data['params'])
        db.session.add(cate)
        db.session.commit()
        return jsonify({"code": 200})
    # {"price":"价格", "guige": "规格"}